package com.zhipu.resetbalance.ui.home.system.inspector.adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.zhipu.resetbalance.R;
import com.zhipu.resetbalance.databinding.ItemInspectorBinding;
import com.zhipu.resetbalance.databinding.ItemPersonnlBinding;
import com.zhipu.resetbalance.listener.ChooseClickCallback;
import com.zhipu.resetbalance.mobile.event.InspectorEntity;
import com.zhipu.resetbalance.ui.home.system.bh.adapter.NumberManagementAdapter;

import java.util.List;

public class InspectorAdapter extends RecyclerView.Adapter<InspectorAdapter.ItemViewHolder>{

    /**
     * 数据
     */
    private List<InspectorEntity> mInspectorEntityList;

    public List<InspectorEntity> getInspectorEntityList() {
        return mInspectorEntityList;
    }

    public void setInspectorEntityList(List<InspectorEntity> mInspectorEntityList) {
        this.mInspectorEntityList = mInspectorEntityList;
        notifyDataSetChanged();
    }

    private ChooseClickCallback mChooseClickCallback;
    public void setChooseClickCallback(ChooseClickCallback mChooseClickCallback) {
        this.mChooseClickCallback = mChooseClickCallback;
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemInspectorBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_inspector, parent, false);
        return new ItemViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        InspectorEntity mInspectorEntity = mInspectorEntityList.get(position);
        if(null != mInspectorEntity){
            //
            holder.binding.InspectorEntityId.setText((position + 1) + "");
            //
            holder.binding.InspectorName.setText(mInspectorEntity.InspectorName);
            //
            holder.binding.creationTime.setText(TimeUtils.millis2String(mInspectorEntity.creationTime));
            //
            holder.binding.Personnel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(null != mChooseClickCallback){
                        mChooseClickCallback.onChooseClickCallback(position);
                    }
                }
            });
        }
    }


    @Override
    public int getItemCount() {

        return null == mInspectorEntityList ? 0 : mInspectorEntityList.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemInspectorBinding binding;
        public ItemViewHolder(@NonNull ItemInspectorBinding mItemInspectorBinding) {
            super(mItemInspectorBinding.getRoot());
            this.binding = mItemInspectorBinding;
        }
    }
}
